<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');

$adm_functions->is_admin_login();
$section='New Gallery';
$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="menudottedline" width="40%">
			<div class="pathway"><img src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
		<td class="menudottedline" align="right">
			<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
				<tr valign="middle" align="center">
					<td>&nbsp;</td>
					<td>
					<a class="toolbar" href="javascript:kliksubmit();">
						<img src="show_files/save.png"  alt="Save" name="save" title="Save" align="middle" border="0" />				<br />Save</a>
					</td>
					<td>&nbsp;</td>
					<td>
						<a class="toolbar" href="admin.php?show=gallery_manager&coll='.$coll.'">
						<img src="show_files/cancel.png"  alt="Cancel" name="cancel" title="Cancel" align="middle" border="0" />				<br />Cancel</a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br />
';

if($inp_title)
{
		if($_FILES['inp_upl_img']['name'])
		{
			$imageexists='N';
			$img_name=basename($_FILES['inp_upl_img']['name']);
			$qryname="select * from albumdetail where nama_gambar='$img_name'";
			$selectname=$dbh->query($qryname);
			while($sqlRowedit=mysql_fetch_object($selectname))
			{
				$imageexists='Y';
			}
			if ($imageexists=='Y') 
			{
				echo '<script>alert("The Filename is already exists, try another filename");</script>';
				$val_title=$inp_title;
				$val_description=$inp_description;
				$val_selected_album=$inp_album;
			}
			else
			{
				$uploaddir = 'assets/albumdetail/';
				$uploadfile = $uploaddir . basename($_FILES['inp_upl_img']['name']);
				move_uploaded_file($_FILES['inp_upl_img']['tmp_name'], $uploadfile);
				$img_name=basename($_FILES['inp_upl_img']['name']);
			}
		} else 	$img_name='';

		if ($imageexists!='Y')
		{
			$dbh->query("insert into albumdetail (
				nama_gambar,
				id_album,
				deskripsi,
				image) values (
				'$inp_title',
				'$inp_album',
				'$inp_description',
				'$img_name')");
			echo '<script>window.location.href="admin.php?show=gallery_manager&coll='.$inp_album.'";</script>';
		}
}
	$QryAlbum="select * from album";
	$ResAlbum=$dbh->query($QryAlbum);
	$val_album='';

	while($sqlRowcoll=mysql_fetch_object($ResAlbum))
	{
		$val_id_album=$sqlRowcoll->id_album;
		$album_name=$sqlRowcoll->nama_album;

		if ($inp_album=='') $val_selected_album=$coll;
		if ($val_id_album==$val_selected_album) $selected='selected'; else $selected='';
		$val_album.='<option value="'.$val_id_album.'" '.$selected.'>'.$album_name.'</option>';
	}

?>